<template>
  <div style="height: 100%;overflow-x: hidden;overflow-y: scroll">
    <div v-if="resumeShow">
      <resume :id="resumeId"></resume>
    </div>
    <el-dialog
        title="输入邀请信息"
        :visible.sync="dialogVisible"
        width="30%">
      <el-form label-position="left" :model="invite"  ref="ruleForm" label-width="80px" class="demo-ruleForm">
        <el-form-item
            label="面试地址"
            prop="address"
            :rules="[{required: true,message:'请输入面试地址',trigger:['blur','change']}]">
          <el-input v-model="invite.address"></el-input>
        </el-form-item>
        <el-form-item
            label="联系电话"
            prop="phone"
            :rules="[{required: true,pattern:/^1[3-9][0-9]{9}$/,message:'请输入合法的联系电话',trigger:['blur','change']}]">
          <el-input v-model="invite.phone"></el-input>
        </el-form-item>
        <el-form-item
            label="面试时间"
            prop="phone"
            :rules="[{required: true,message:'请输入面试时间',trigger:['blur','change']}]">
          <el-input v-model="invite.time"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
    <el-button @click="dialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="submitInvite">确 定</el-button>
  </span>
    </el-dialog>
    <el-table
        v-if="!resumeShow"
        :data="delivers"
        stripe
        header-align="center"
        style="width: 100%">
      <el-table-column
          align="center"
          label="投递时间"
          width="180">
        <template slot-scope="scope">
          {{scope.row.createTime|formatDate}}
        </template>
      </el-table-column>
      <el-table-column
          prop="resume.name"
          align="center"
          label="姓名"
          width="180">
      </el-table-column>
      <el-table-column
          prop="resume.degree"
          align="center"
          label="学历">
      </el-table-column>
      <el-table-column
          prop="resume.city"
          align="center"
          label="所在城市">
      </el-table-column>
      <el-table-column
          label="处理状态">
        <template slot-scope="scope">
          {{getState(scope.row.state)}}
        </template>
      </el-table-column>
      <el-table-column
          width="280"
          label="操作">
        <template slot-scope="scope">
          <el-button type="primary" @click="lookResume(scope.row.resume.id)" size="mini">查看简历</el-button>
          <el-button type="success" @click="openInvite(scope.row.resume,scope.row.id)"  size="mini">邀请面试</el-button>
          <el-button type="danger" @click="rejectHandle(scope.row.id)" size="mini">拒绝</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import {getDelivers, sendInvite} from "@/api/recruitment";
import resume from "@/views/Management/Company/LookResume/index"
export default {
  name: "deliversList",
  components:{
    resume
  },
  data(){
    return{
      resumeId:0,
      resumeShow:false,
      dialogVisible:false,
      delivers:[],
      resume:{},
      invite:{
        studentName:'',
        companyName:'',
        address:'',
        time:'',
        phone:'',
        email:'',
        deliverId:0,
        state:0
      }
    }
  },
  created() {
    getDelivers(this.$route.query.id).then(res=>{
      this.delivers=res.data.extend.delivers
    })
  },
  methods:{
    lookResume(id){
      this.resumeId=id
      this.resumeShow=true
    },
    getState(state){
      console.log(state,'状态')
      if(state==0){
        return '未处理'
      }else if(state==1){
        return '已邀请面试'
      }else {
        return '已拒绝'
      }
    },
    rejectHandle(id){
      this.invite.state=-1
      this.invite.deliverId=id
      sendInvite(this.invite).then(res=>{
        this.$message.warning(res.data.msg)
        getDelivers(this.$route.query.id).then(res=>{
          this.delivers=res.data.extend.delivers
        })
      })
    },
    openInvite(resume,id){
      Object.keys(this.invite).forEach(key=>{
        this.invite[key]=''
      })
      this.invite.deliverId=id
      this.resume=resume
      if(resume.email){
        this.dialogVisible=true
      }else {
        this.$message.warning("该投递缺乏联系方式,无法邀请~")
      }
    },
    submitInvite(){
      this.$refs['ruleForm'].validate((valid) => {``
        if (valid) {
          let resume=this.resume
          this.invite.email=resume.email
          this.invite.studentName=resume.name
          this.invite.state=1
          this.invite.companyName=this.$store.getters["user/getUser"].userName
          sendInvite(this.invite).then(res=>{
            this.$message.warning(res.data.msg)
            this.dialogVisible=false
            getDelivers(this.$route.query.id).then(res=>{
              this.delivers=res.data.extend.delivers
            })
          })
        }else {
          return false;
        }
      });
    },

  }
}
</script>

<style scoped>

</style>
